<?php
use Yii\helpers\Html;
use Yii\helpers\Url;
use yii\bootstrap\ActiveForm;
$this->title = '底部导航';
?>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav') ?>
        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">底部导航</h1>
            <div class="pull-right">

               
    <button class="btn btn-success btn-sm pull-right" id="add-navigation-btn" data-toggle="modal" data-target="#friendlinkadd" data-url="/admin/setting/navigation/create?type=foot">新增底部导航</button>

            </div>
          </div>
            <div aria-hidden="false" style="display: none;" id="friendlinkadd" class="modal in"><div class="modal-dialog ">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h4 class="modal-title">新增底部导航</h4>
                        </div>
                        <div class="modal-body">
                            <?php
                            $form = ActiveForm::begin([
                                'options' => ['class' => 'form-horizontal','id'=>'site-form','enctype' => 'multipart/form-data'],
                                'action'=>Url::to(['system/friendlinkadd']),
                                'method'=>'post',
                                'fieldConfig' => [
                                    'template' => '<div class="row form-group"><div class="col-md-3 control-label">{label}</div><div class="col-md-8 controls">{input}{error}<div class="help-block" style="display:none;"></div></div></div><p></p>'
                                ],
                            ]);
                            ?>

                            <?= $form->field($model, 'link_name', ['inputOptions'=>['placeholder'=>'']])->textInput() ?>

                            <?= $form->field($model, 'link_url', ['inputOptions'=>['placeholder'=>'']])->textInput() ?>

                            <?= $form->field($model, 'link_logo', ['inputOptions'=>['placeholder'=>'']])->fileInput() ?>

                            <?= $form->field($model, 'link_order', ['inputOptions'=>['placeholder'=>'']])->textInput() ?>
                            <div class="modal-footer">
                            <?= Html::Button('取消', ['class' => 'btn btn-link','data-dismiss'=>'modal']) ?>
                            <?= Html::submitButton('保存', ['class' => 'btn btn-primary']) ?>
                            </div>
                            <?php ActiveForm::end();?>
                        </div>

                    </div>
                </div>
            </div>
            <!--
                <div aria-hidden="false" style="display: block;" id="modal" class="modal in"><div class="modal-dialog ">
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h4 class="modal-title">新增底部导航

</h4>
    </div>
    <div class="modal-body">
  <form data-widget-cid="widget-0" novalidate="novalidate" class="form-horizontal" id="navigation-form" action="/admin/setting/navigation/create" method="post">



 <div class="row form-group">
  <div class="col-md-3 control-label"><label for="name">名称</label></div>
  <div class="col-md-8 controls">
    <input data-explain="" data-widget-cid="widget-1" class="form-control" id="name" value="" name="name" type="text"><div class="help-block" style="display:none;"></div></div>
</div>
<p></p>

<div class="row form-group">
  <div class="col-md-3 control-label"><label for="url">链接地址</label></div>
  <div class="col-md-8 controls"> <input class="form-control" id="url" value="http://" name="url" type="text"></div>
</div>

<p></p>

<input name="type" value="foot" type="hidden">

<div class="row form-group">
          <div class="col-md-3 control-label"><label>新开窗口</label></div>
          <div class="col-md-8 controls radios">
            <div id="isNewWin">
              <input name="isNewWin" value="0" checked="checked" type="radio">
              <label>否</label>
              <input name="isNewWin" value="1" type="radio">
              <label>是</label>
            </div>
          </div>
</div>

<div class="row form-group">
      <div class="col-md-3 control-label">
        <label>状态</label>
      </div>
      <div class="col-md-8 controls radios">
        <div id="isOpen">
          <input name="isOpen" value="1" checked="checked" type="radio">
          <label>开启</label>
          <input name="isOpen" value="0" type="radio">
          <label>关闭</label>
        </div>
      </div>
</div>
<input name="parentId" value="0" type="hidden">
<input name="_csrf_token" value="051aa80ad5d4b2a3ccd93fbc12b24aa826272078" type="hidden">

  </form>



</div>
          <div class="modal-footer">  <button type="button" class="btn btn-link" data-dismiss="modal">取消</button>
  <button id="navigation-save-btn" data-submiting-text="正在提交" type="submit" class="btn btn-primary" data-toggle="form-submit" data-target="#navigation-form">保存</button>
</div>
      </div>
</div></div>
            -->

	        <div id="friendlinkupdate" class="modal fade"></div>
           <?php echo $this->render('_sitesetting') ?>
          
<table id="navigation-table" class="table table-striped table-hover navigation-table">
	<thead>
	  <tr>
	    <th width="50%">名称</th>
		  <th width="20%">排序</th>
	    <th width="30%">操作</th>
	  </tr>
	</thead>
    
 	<tbody data-update-seqs-url="/admin/setting/navigation/seqs/update">
    <?php if($friendlink){ ?>
        <?php foreach ($friendlink as $v) { ?>

            <tr class=" has-subItems " id="navigations-tr-27" data-id="27" data-parent-id="0">
                <td style="vertical-align: middle;">
                    <span class="glyphicon glyphicon-resize-vertical"></span>
                    <a href="<?= $v['link_url'] ?>" target="_blank"><?= $v['link_name'] ?></a>
                </td>
	            <td><?= $v['link_order'] ?></td>
                <td>
                    <button class="btn btn-sm btn-default edit-btn friendlinkupdate" data-url="/admin/setting/navigation/27/update" data-toggle="modal" type="<?= $v['link_id'] ?>" data-target="#friendlinkupdate">编辑</button>
                    <button class="btn btn-sm btn-default delete-btn friendlinkdel" data-url="/admin/setting/navigation/27/delete" data-target="27" value="<?= $v['link_id'] ?>">删除</button>
                </td>
            </tr>

        <?php
        }
        ?>

    <?php }else{ ?>
  	    <tr><td colspan="20"><div class="empty">暂无导航记录</div></td></tr>
    <?php } ?>
</tbody>
</table>
        </div>
    </div>
</div>
<script>
	//友情链接删除
	$(".friendlinkdel").click(function(){
		if(confirm("确定要删除此导航吗？")){
			var config_id = $(this).attr("value");
			$.ajax({
				type: "POST",
				url: "<?php echo  \Yii::$app->urlManager->createUrl('system/friendlinkdel') ?>",
				data: "config_id="+config_id,
				success: function(msg){
					if(msg == 1)
					{
						location.reload();
					}else if(msg == 0)
					{
						alert('删除失败');
					}else
					{
						alert('没有传值');
					}
				}
			});
		}
	})

	//友情链接修改页面
	$(".friendlinkupdate").click(function(){
		var link_id=$(this).attr("type");
		$.ajax({
			type: "POST",
			url: "<?php echo  \Yii::$app->urlManager->createUrl('system/friendlinkupdate') ?>",
			data: "link_id="+link_id,
			success: function(msg){
				$("#friendlinkupdate").html(msg);
			}
		});
	})
</script>